package jp.co.hcs.attendancemanagement.inputdailyattendance.logic;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import jp.co.hcs.attendancemanagement.AMConstants;
import jp.co.hcs.attendancemanagement.AMResourceKeyConstants;
import jp.co.hcs.attendancemanagement.AMResourceManager;
import jp.co.hcs.attendancemanagement.StrutsMessageConstants;
import jp.co.hcs.attendancemanagement.data.entity.EmployeeVacation;
import jp.co.hcs.attendancemanagement.data.entity.Job;
import jp.co.hcs.attendancemanagement.data.entity.RestTimeActual;
import jp.co.hcs.attendancemanagement.data.entity.WorkingTimeMaster;
import jp.co.hcs.attendancemanagement.inputdailyattendance.actionform.InputDailyAttendanceForm;
import jp.co.hcs.attendancemanagement.inputdailyattendance.logic.dto.DailyWorkingActualResultDTO;
import jp.co.hcs.attendancemanagement.inputdailyattendance.logic.dto.EmployeeCompanyDTO;
import jp.co.hcs.attendancemanagement.inputdailyattendance.logic.dto.StampActualResultDTO;
import jp.co.hcs.attendancemanagement.util.DateUtil;
import jp.co.hcs.attendancemanagement.util.StringUtil;
import jp.co.hcs.attendancemanagement.util.TimeUtil;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

public class ReCalculateDailyWorkingLogic extends InputDailyWorkingLogicBase {
    /**
     * Re calculate.
     * 
     * @param form the form
     * @return the action messages
     * @throws SQLException the sQL exception
     */
    public ActionMessages reCalculate(InputDailyAttendanceForm form) throws SQLException {
      String userLoggedIn = form.getUserId();

      ActionMessages errors = new ActionMessages();

      // --get fixed working time
      DailyWorkingActualResultDTO dailyWorkingActual = form.getTimeDTO();

      float fixedWork = (float) 7.5;
      if (!StringUtil.isEmpty(dailyWorkingActual.getTimeDivision())) {
        WorkingTimeMaster timeMaster =
              getWorkingTimeMasterDAO().selectWorkingTimeMasterByPrimaryKey(
                  dailyWorkingActual.getTimeDivision());
        
        if (timeMaster != null) {
          dailyWorkingActual.setPlannedWorkingStartTime(
                  DateUtil.convertDateToHourFormat(timeMaster.getStartTime()));
          dailyWorkingActual.setPlannedWorkingEndTime(
                  DateUtil.convertDateToHourFormat(timeMaster.getEndTime()));
          dailyWorkingActual.setPlannedWorkingTime(
                  DateUtil.convertDateToHourFormat(timeMaster.getFixedWorkingTime()));
          dailyWorkingActual.setOvertimeAutomaticApply(
                  DateUtil.convertDateToHourFormat(timeMaster.getAutoOvertimeTime()));
        
          fixedWork = TimeUtil.convertTimeFromHHMM(DateUtil.convertDateToHourFormat(timeMaster.getFixedWorkingTime()));
        }
      }
      
      // get attendance classification
      // --get job division
      String jobType = dailyWorkingActual.getJobDivision();

      if (AMConstants.PAID_LEAVE.equals(jobType) || AMConstants.HALF_MORNING_LEAVE.equals(jobType)
          || AMConstants.HALF_AFTERNOON_LEAVE.equals(jobType)
          || AMConstants.TIME_PAID_LEAVE.equals(jobType)) {
        // get employee company info
        EmployeeCompanyDTO employeeCompanyDTO = form.getInitDTO();
          
        Date startDayOfyear = DateUtil.parseDateMMdd(employeeCompanyDTO.getStartDayOfYear(), form.getYear());
        
        // get rest time data
        // --get rest time actual result
        List<RestTimeActual> listRestTimeActual =
            getRestTimeActualDAO().getValidRestTimeActualList(userLoggedIn, startDayOfyear);

        // --get paid leave info data for employee
        EmployeeVacation employeeVacation =
            getEmployeeVacationDAO().selectEmployeeVacationByPrimaryKey(userLoggedIn);

        // check rest time remaining
        // --calculate total of rest time
        int totalPaidLeave = 0;
        int totalHalfPaidLeave = 0;
        int totalTimePaidLeavePerHour = 0;
        int totalTimePaidLeavePerMinute = 0;
        if (listRestTimeActual != null) {
          for (RestTimeActual rta : listRestTimeActual) {
            if (AMConstants.PAID_LEAVE.equals(rta.getRestType())) {
              totalPaidLeave += rta.getRestTakingDays().intValue();
            } else if (AMConstants.HALF_MORNING_LEAVE.equals(rta.getRestType())
                || AMConstants.HALF_AFTERNOON_LEAVE.equals(rta.getRestType())) {
              totalHalfPaidLeave++;
            } else if (AMConstants.TIME_PAID_LEAVE.equals(rta.getRestType())) {
              totalTimePaidLeavePerHour += DateUtil.getHours(rta.getRestTakingTime());
              totalTimePaidLeavePerMinute += DateUtil.getMinutes(rta.getRestTakingTime());
            }
          }
        }
        int totalTimePaidLeavePerDay =
            (int) ((totalTimePaidLeavePerHour + totalTimePaidLeavePerMinute / 60) / fixedWork);
        int totalLeave = totalPaidLeave + totalHalfPaidLeave / 2 + totalTimePaidLeavePerDay;

        // --check kha nang xin nghi phep
        int vacationDays = 0;
        if (employeeVacation != null) {
          int currentYearVacation = employeeVacation.getCurrentYearVacation() != null ? employeeVacation.getCurrentYearVacation() : 0;
          int lastYearLeftVacation = employeeVacation.getLastYearLeftVacation() != null ? employeeVacation.getLastYearLeftVacation() : 0;
          vacationDays = currentYearVacation + lastYearLeftVacation;
        }
        if (vacationDays - totalLeave < 1) {
          errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
              StrutsMessageConstants.ALARM_W1051_ERROR, AMResourceManager
                  .getMessage(AMResourceKeyConstants.MSG_PAID_HOLIDAY)));
          return errors;
        }
        // --check kha nang xin nghi nua ngay
        if (employeeCompanyDTO.getHalfRestLimitedNumber() - totalHalfPaidLeave < 1) {
          errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
              StrutsMessageConstants.ALARM_W1051_ERROR, AMResourceManager
                  .getMessage(AMResourceKeyConstants.MSG_HALF_HOLIDAY)));
          return errors;
        }
      }

      // get du lieu phan loai thoi gian
      // --khoi tao truong phan loai thoi gian da get
      // --get truong phan loai thoi gian
      WorkingTimeMaster workingTimeMaster =
          getWorkingTimeMasterDAO().selectWorkingTimeMasterByPrimaryKey(
              dailyWorkingActual.getTimeDivision());

      // edit working time
      int roundingTime = 0;
      if (roundingTime == 0) {
        roundingTime = workingTimeMaster.getRoundTime();
      }
      if (roundingTime == 0) {
        roundingTime = 60;
      }

      // current date
      String currentMonthDay = form.getMonth() + "/" + form.getDay();

      String workingStartTime = dailyWorkingActual.getWorkingStartTime();
      if (!StringUtil.isEmpty(workingStartTime)) {
        workingStartTime = StringUtil.fullWidthNumberToHalfWidthNumber(workingStartTime);
        dailyWorkingActual.setWorkingStartTime(workingStartTime);
      }
      String workingStartDay = dailyWorkingActual.getWorkingStartDay();
      if (!StringUtil.isEmpty(workingStartDay)) {
        workingStartDay = StringUtil.fullWidthNumberToHalfWidthNumber(workingStartDay);
        dailyWorkingActual.setWorkingStartDay(workingStartDay);
      }
      String workingEndTime = dailyWorkingActual.getWorkingEndTime();
      if (!StringUtil.isEmpty(workingEndTime)) {
        workingEndTime = StringUtil.fullWidthNumberToHalfWidthNumber(workingEndTime);
        dailyWorkingActual.setWorkingEndTime(workingEndTime);
      }
      String workingEndDay = dailyWorkingActual.getWorkingEndDay();
      if (!StringUtil.isEmpty(workingEndDay)) {
        workingEndDay = StringUtil.fullWidthNumberToHalfWidthNumber(workingEndDay);
        dailyWorkingActual.setWorkingEndDay(workingEndDay);
      }

      String[] timeSpliter;
      int tmpHour;
      int tmpMinute;

      if (!StringUtil.isEmpty(workingStartTime) && !StringUtil.isEmpty(workingStartDay)) {
        // --auto convert round time start
        timeSpliter = workingStartTime.split(":");
        tmpHour = Integer.parseInt(timeSpliter[0]);
        tmpMinute = Integer.parseInt(timeSpliter[1]);
        tmpMinute =
            (tmpMinute / roundingTime) * roundingTime
                + (tmpMinute % roundingTime > 0 ? roundingTime : 0);
        if (tmpMinute == 60) {
          tmpHour = tmpHour + 1;
          tmpMinute = 0;
        }
        if (tmpHour == 24 && tmpMinute == 0) {
          tmpHour = 0;
          tmpMinute = 0;
          // workingStartDay + 1
          workingStartDay = DateUtil.addSomeDays(workingStartDay, form.getYear(), 1);
        }
        workingStartTime =
            StringUtil.parseZeroString(tmpHour) + ":" + StringUtil.parseZeroString(tmpMinute);
        dailyWorkingActual.setWorkingStartTime(workingStartTime);
      }

      if (!StringUtil.isEmpty(workingEndTime) && !StringUtil.isEmpty(workingEndDay)) {
        // --auto convert round time end
        timeSpliter = workingEndTime.split(":");
        tmpHour = Integer.parseInt(timeSpliter[0]);
        tmpMinute = Integer.parseInt(timeSpliter[1]);
        tmpMinute = (tmpMinute / roundingTime) * roundingTime;
        workingEndTime =
            StringUtil.parseZeroString(tmpHour) + ":" + StringUtil.parseZeroString(tmpMinute);
        dailyWorkingActual.setWorkingEndTime(workingEndTime);
      }

      StampActualResultDTO saDto = form.getStampActualResultDTO();

      String workInDate = saDto.getComingWorkDay();
      String workInTime = saDto.getComingWorkTime();

      // --check tinh tuong thich giua thoi gian di lam va thoi gian start cong viec
      if (!StringUtil.isEmpty(workingStartDay) && !StringUtil.isEmpty(workingStartTime)
          && !StringUtil.isEmpty(workInDate) && !StringUtil.isEmpty(workInTime)
          && !saDto.getChokkoFlag() && !dailyWorkingActual.getCommutingDelayFlag()) {
        boolean dateSwitchNextDayFlag = workingTimeMaster.getIsYesterday();
        if (dateSwitchNextDayFlag) {
          String dateChangeTime =
              DateUtil.convertDateToHourFormat(workingTimeMaster.getDateChangeTime());
          if ((workingStartDay.equals(workInDate) && workingStartDay.equals(currentMonthDay)
              && TimeUtil.isLessThanOrEqual(workInTime, workingStartTime) && TimeUtil
                .isGreaterThanOrEqual(workingStartTime, dateChangeTime))
              || (workingStartDay.equals(workInDate)
                  && DateUtil.isBefore(currentMonthDay, workingStartDay)
                  && TimeUtil.isLessThanOrEqual(workInTime, workingStartTime) && TimeUtil.isLessThan(
                  workingStartTime, dateChangeTime))
              || (DateUtil.isBefore(workInDate, workingStartDay) && TimeUtil.isLessThan(
                  workingStartTime, dateChangeTime))) {
            // time is valid
          } else {
            errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
                StrutsMessageConstants.ALARM_W1053_ERROR, AMResourceManager
                    .getMessage(AMResourceKeyConstants.FIELD_STARTWORKINGTIME)));
            return errors;
          }
        } else {
          if (workingStartDay.equals(workInDate)
              && TimeUtil.isLessThanOrEqual(workInTime, workingStartTime)) {
            // time is valid
          } else {
            errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
                StrutsMessageConstants.ALARM_W1053_ERROR, AMResourceManager
                    .getMessage(AMResourceKeyConstants.FIELD_STARTWORKINGTIME)));
            return errors;
          }
        }
      }

      String leaveOutDate = saDto.getLeavingWorkDay();
      String leaveOutTime = saDto.getLeavingWorkTime();

      // --check tinh tuong thich giua leave out time va work end time
      if (!StringUtil.isEmpty(workingEndDay) && !StringUtil.isEmpty(workingEndTime)
          && !saDto.getChokkiFlag() && !StringUtil.isEmpty(leaveOutDate)
          && !StringUtil.isEmpty(leaveOutTime)) {
        if ((workingEndDay.equals(leaveOutDate) && TimeUtil.isGreaterThanOrEqual(leaveOutTime,
            workingEndTime))
            || DateUtil.isBefore(workingEndDay, leaveOutDate)) {
          // time is valid
        } else {
          errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
              StrutsMessageConstants.ALARM_W1053_ERROR, AMResourceManager
                  .getMessage(AMResourceKeyConstants.FIELD_ENDWORKINGTIME)));
          return errors;
        }
      }

      // --check tinh tuong thich giua work start time va work end time
      if (!StringUtil.isEmpty(workingStartDay) && !StringUtil.isEmpty(workingStartTime)
          && !StringUtil.isEmpty(workingEndDay) && !StringUtil.isEmpty(workingEndTime)) {
        if (workingStartDay.equals(workingEndDay)
            && TimeUtil.isGreaterThanOrEqual(workingStartTime, workingEndTime)) {
          errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
              StrutsMessageConstants.ALARM_W1053_ERROR, AMResourceManager
                  .getMessage(AMResourceKeyConstants.FIELD_STARTENDWORKINGTIME)));
          return errors;
        } else if (DateUtil.isBefore(workingEndDay, workingStartDay)) {
          errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
              StrutsMessageConstants.ALARM_W1053_ERROR, AMResourceManager
                  .getMessage(AMResourceKeyConstants.FIELD_STARTENDWORKINGTIME)));
          return errors;
        }
      }

      // calculate working time
      if ((!StringUtil.isEmpty(jobType) && !StringUtil.isEmpty(dailyWorkingActual.getTimeDivision())
          && !StringUtil.isEmpty(workingStartDay) && !StringUtil.isEmpty(workingStartTime)
          && !StringUtil.isEmpty(workingEndDay) && !StringUtil.isEmpty(workingEndTime))
          || form.isWorkingTimeCheckExclusionFlag()) {
        calculateWorkingTime(form);
      }

      return errors;
    }
    
    /**
     * Calculate working time.
     * 
     * @param form the form
     * @throws SQLException the sQL exception
     */
    public void calculateWorkingTime(InputDailyAttendanceForm form) throws SQLException {
      DailyWorkingActualResultDTO dailyWorkingActual = form.getTimeDTO();

      WorkingTimeMaster workingTimeMaster =
          getWorkingTimeMasterDAO().selectWorkingTimeMasterByPrimaryKey(
              dailyWorkingActual.getTimeDivision());
      String lunchBreakStartTime =
          DateUtil.convertDateToHourFormat(workingTimeMaster.getRestStartTime());
      String lunchBreakEndTime = DateUtil.convertDateToHourFormat(workingTimeMaster.getRestEndTime());

      // 10.1 get attendance classification
      Job jobDivision = getJobDAO().selectJobByPrimaryKey(dailyWorkingActual.getJobDivision());

      // 10.2 switching work hours for work
      String workingStartTime = dailyWorkingActual.getWorkingStartTime();
      String workingEndTime = dailyWorkingActual.getWorkingEndTime();
      String startTimeForWorking = workingStartTime;
      String endTimeForWorking = workingEndTime;
      if (jobDivision.getIsMorningRest()) {
        if (TimeUtil.isGreaterThanOrEqual(lunchBreakEndTime, workingStartTime)) {
          startTimeForWorking = lunchBreakEndTime;
        } else {
          startTimeForWorking = workingStartTime;
        }
        endTimeForWorking = workingEndTime;
      } else if (jobDivision.getIsAfternoonRest()) {
        String startTime = DateUtil.convertDateToHourFormat(workingTimeMaster.getStartTime());
        if (TimeUtil.isGreaterThanOrEqual(startTime, workingStartTime)) {
          startTimeForWorking = startTime;
        } else {
          startTimeForWorking = workingStartTime;
        }
        if (TimeUtil.isGreaterThanOrEqual(workingEndTime, lunchBreakStartTime)) {
          endTimeForWorking = lunchBreakStartTime;
        } else {
          endTimeForWorking = workingEndTime;
        }
      }

      // 10.3 get leave time
      String leaveTime = "00:00";
      if (AMConstants.PAID_LEAVE.equals(jobDivision.getJobId())
          || AMConstants.SUBSTITUTE_LEAVE.equals(jobDivision.getJobId())) {
        leaveTime = DateUtil.convertDateToHourFormat(workingTimeMaster.getFixedWorkingTime());
      } else if (AMConstants.HALF_MORNING_LEAVE.equals(jobDivision.getJobId())) {
        leaveTime = DateUtil.convertDateToHourFormat(workingTimeMaster.getMorningRestTime());
      } else if (AMConstants.HALF_AFTERNOON_LEAVE.equals(jobDivision.getJobId())) {
        leaveTime = DateUtil.convertDateToHourFormat(workingTimeMaster.getAfternoonRestTime());
      } else if (AMConstants.TIME_PAID_LEAVE.equals(jobDivision.getJobId())) {
        leaveTime = dailyWorkingActual.getPaidHoliday();
      }
      form.setLeaveTime(leaveTime);

      // 10.4 get fixed rest time
      String fixedRestTime = "00:00";
      String screenMonthDay = form.getMonth() + "/" + form.getDay();
      String workingStartDate = dailyWorkingActual.getWorkingStartDay();
      String workingEndDate = dailyWorkingActual.getWorkingEndDay();
      // --10.4.1 get lunch rest time
      if (!jobDivision.getIsMorningRest() && !jobDivision.getIsAfternoonRest()
          && !StringUtil.isEmpty(lunchBreakStartTime) && !StringUtil.isEmpty(lunchBreakEndTime)) {
        if (screenMonthDay.equals(workingStartDate) && screenMonthDay.equals(workingEndDate)) {
          if (TimeUtil.isLessThan(lunchBreakStartTime, workingStartTime)
              && TimeUtil.isLessThanOrEqual(workingStartTime, lunchBreakEndTime)) {
            fixedRestTime =
                TimeUtil.sum(fixedRestTime, TimeUtil.sub(lunchBreakEndTime, workingStartTime));
          } else if (TimeUtil.isLessThan(workingStartTime, lunchBreakStartTime)
              && TimeUtil.isLessThanOrEqual(lunchBreakEndTime, workingEndTime)) {
            fixedRestTime =
                TimeUtil.sum(fixedRestTime, TimeUtil.sub(lunchBreakEndTime, lunchBreakStartTime));
          } else if (TimeUtil.isLessThan(workingStartTime, lunchBreakStartTime)
              && TimeUtil.isLessThanOrEqual(workingEndTime, lunchBreakEndTime)) {
            fixedRestTime =
                TimeUtil.sum(fixedRestTime, TimeUtil.sub(workingEndTime, lunchBreakStartTime));
          }
        } else if (screenMonthDay.equals(workingStartDate)
            && DateUtil.isBefore(screenMonthDay, workingEndDate)) {
          if (TimeUtil.isLessThanOrEqual(lunchBreakStartTime, workingStartTime)) {
            fixedRestTime =
                TimeUtil.sum(fixedRestTime, TimeUtil.sub(lunchBreakEndTime, workingStartTime));
          } else if (TimeUtil.isGreaterThan(lunchBreakStartTime, workingStartTime)) {
            fixedRestTime =
                TimeUtil.sum(fixedRestTime, TimeUtil.sub(lunchBreakEndTime, workingStartTime));
          }
        }
      }

      // --10.4.2 get rest time 1
      String restStartTime1 = DateUtil.convertDateToHourFormat(workingTimeMaster.getRest1StartTime());
      String restEndTime1 = DateUtil.convertDateToHourFormat(workingTimeMaster.getRest1EndTime());
      if (!StringUtil.isEmpty(restStartTime1) && !StringUtil.isEmpty(restEndTime1)) {
        if (workingStartDate.equals(workingEndDate)
            && TimeUtil.isLessThanOrEqual(workingStartTime, restStartTime1)
            && TimeUtil.isLessThanOrEqual(restEndTime1, workingEndTime)) {
          fixedRestTime = TimeUtil.sum(fixedRestTime, TimeUtil.sub(restEndTime1, restStartTime1));
        } else if (DateUtil.isBefore(workingStartDate, workingEndDate)
            && (TimeUtil.isLessThanOrEqual(workingStartTime, restStartTime1) || TimeUtil
                .isLessThanOrEqual(workingEndTime, restEndTime1))) {
          fixedRestTime = TimeUtil.sum(fixedRestTime, TimeUtil.sub(restEndTime1, restStartTime1));
        }
      }

      // --10.4.3 get rest time 2
      String restStartTime2 = DateUtil.convertDateToHourFormat(workingTimeMaster.getRest2StartTime());
      String restEndTime2 = DateUtil.convertDateToHourFormat(workingTimeMaster.getRest2EndTime());
      if (!StringUtil.isEmpty(restStartTime2) && !StringUtil.isEmpty(restEndTime2)) {
        if (workingStartDate.equals(workingEndDate)
            && TimeUtil.isLessThanOrEqual(workingStartTime, restStartTime2)
            && TimeUtil.isLessThanOrEqual(restEndTime2, workingEndTime)) {
          fixedRestTime = TimeUtil.sum(fixedRestTime, TimeUtil.sub(restEndTime2, restStartTime2));
        } else if (DateUtil.isBefore(workingStartDate, workingEndDate)
            && (TimeUtil.isLessThanOrEqual(workingStartTime, restStartTime2) || TimeUtil
                .isLessThanOrEqual(workingEndTime, restEndTime2))) {
          fixedRestTime = TimeUtil.sum(fixedRestTime, TimeUtil.sub(restEndTime2, restStartTime2));
        }
      }

      // --10.4.4 get rest time 3
      String restStartTime3 = DateUtil.convertDateToHourFormat(workingTimeMaster.getRest3StartTime());
      String restEndTime3 = DateUtil.convertDateToHourFormat(workingTimeMaster.getRest3EndTime());
      if (!StringUtil.isEmpty(restStartTime3) && !StringUtil.isEmpty(restEndTime3)) {
        if (workingStartDate.equals(workingEndDate)
            && TimeUtil.isLessThanOrEqual(workingStartTime, restStartTime3)
            && TimeUtil.isLessThanOrEqual(restEndTime3, workingEndTime)) {
          fixedRestTime = TimeUtil.sum(fixedRestTime, TimeUtil.sub(restEndTime3, restStartTime3));
        } else if (DateUtil.isBefore(workingStartDate, workingEndDate)
            && (TimeUtil.isLessThanOrEqual(workingStartTime, restStartTime3) || TimeUtil
                .isLessThanOrEqual(workingEndTime, restEndTime3))) {
          fixedRestTime = TimeUtil.sum(fixedRestTime, TimeUtil.sub(restEndTime3, restStartTime3));
        }
      }

      // 10.5 edit working time
      String netWorkingTime = "00:00";
      boolean isNotCheckWorkingTime = form.isWorkingTimeCheckExclusionFlag();
      String screenRestTime = dailyWorkingActual.getRestTime();
      if (!isNotCheckWorkingTime) {
        if (workingStartDate.equals(workingEndDate)) {
          netWorkingTime =
              TimeUtil.sub(TimeUtil.sub(TimeUtil.sub(endTimeForWorking, startTimeForWorking),
                  fixedRestTime), screenRestTime);
        } else if (DateUtil.isBefore(workingStartDate, workingEndDate)) {
          netWorkingTime =
              TimeUtil.sub(TimeUtil.sub(TimeUtil.sub("24:00", TimeUtil.sum(endTimeForWorking,
                  startTimeForWorking)), fixedRestTime), screenRestTime);
        }
      }

      String workingTime = TimeUtil.sum(netWorkingTime, leaveTime);
      dailyWorkingActual.setWorkingTime(workingTime);

      // 10.6 edit working time information

      // 11.1 init working time information
      dailyWorkingActual.setFixedWorkingTime(TimeUtil.TIME_EMPTY);
      dailyWorkingActual.setInsufficentTime(TimeUtil.TIME_EMPTY);
      dailyWorkingActual.setOvertime(TimeUtil.TIME_EMPTY);
      dailyWorkingActual.setNightWorkTime(TimeUtil.TIME_EMPTY);
      dailyWorkingActual.setSatWorkingTime(TimeUtil.TIME_EMPTY);
      dailyWorkingActual.setSatNightWorkTime(TimeUtil.TIME_EMPTY);
      dailyWorkingActual.setSubstituteHolidayTime(TimeUtil.TIME_EMPTY);
      dailyWorkingActual.setHolidayWorkTime(TimeUtil.TIME_EMPTY);
      dailyWorkingActual.setHolidayNightWorkTime(TimeUtil.TIME_EMPTY);
      form.setAnnouncement("");

      if (!isNotCheckWorkingTime) {
        // 11.2 edit fixed working time
        if (AMConstants.HOLIDAY_WORKING.equals(jobDivision.getJobId())
            || AMConstants.SATURDAY_WORKING.equals(jobDivision.getJobId())) {
          dailyWorkingActual.setSubstituteHolidayTime(netWorkingTime);
        } else {
          String fixedTimeForCalculate =
              TimeUtil.sub(dailyWorkingActual.getPlannedWorkingTime(), leaveTime);
          String fixedWorkingTime;
          String overtime;
          String lackingTime;
          if (TimeUtil.isGreaterThanOrEqual(fixedTimeForCalculate, netWorkingTime)) {
            fixedWorkingTime = netWorkingTime;
            overtime = "00:00";
            lackingTime = TimeUtil.sub(fixedTimeForCalculate, netWorkingTime);
          } else {
            fixedWorkingTime = fixedTimeForCalculate;
            overtime = TimeUtil.sub(netWorkingTime, fixedTimeForCalculate);
            lackingTime = "00:00";
          }
          dailyWorkingActual.setFixedWorkingTime(fixedWorkingTime);
          dailyWorkingActual.setOvertime(overtime);
          dailyWorkingActual.setInsufficentTime(lackingTime);
        }
      }
    }
}
